<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>打印配送标签</title>
    <script src="/jquery-1.8.3.min.js"></script>
    <script src="/printThis.js"></script>
    <link rel="stylesheet" href="/print.css"/>
</head>
<body>
<div id="receiptPrintArea0">
    <table width="100%" class="printTable" id="table0">
        <tr>
            <td width="100%"><span class="router"></span></td>
        </tr>
        <tr>
            <td width="100%"><span class="distributionDate"></span></td>
        </tr>
        <tr>
            <td width="100%"><span class="customer"></span></td>
        </tr>
        <tr>
            <td width="100%"><span class="foodName"></span></td>
        </tr>
        <tr>
            <td width="100%"><span class="amount"></span></td>
        </tr>
    </table>
</div>
<script th:inline="javascript">
    var params = [[${params}]];
    var router = params.router;
    var routerName = params.routerName;
    var beginDistributionDate = params.beginDistributionDate;
    var endDistributionDate = params.endDistributionDate;
    var foodMaterialId = params.foodMaterialId;
    var foodMaterialName = params.foodMaterialName;
    var supplierId = params.supplierId ;
    var supplierName = params.supplierName ;
    var backAddress = params.backAddress;
    var printChoice = params.printChoice;
    function print() {
        $("#receiptPrintArea0").printThis({
            debug: false,
            importCSS: true,
            importStyle: true,
            printContainer: true,
            pageTitle: "",
            removeInline: false,
            //printDelay: 333,
            header: null,
            formValues: true
        });
    }
    $.ajax({
            url: backAddress + "/api/order/querySupplySummaryBySupplier",
            data : JSON.stringify({
                "beginDistributionDate" : beginDistributionDate,
                "endDistributionDate" : endDistributionDate,
                "router" : router,
                "foodMaterialId" : foodMaterialId,
                "supplierId" : supplierId
            }),
            type: "post",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (data) {
                var index = 0 ;
                for (var i = 0 ; i < data.data.data.length ; i++) {
                    for (var j = 0 ; j < data.data.header.length ; j++) {
                        if (data.data.data[i][data.data.header[j]] === null) continue;
                        index++;
                    }
                }
                index--;
                for (var i = 0 ; i < index ; i++) {
                    var node = $("#table0").clone(true);
                    $("#receiptPrintArea0").append($("<br/>"));
                    $("#receiptPrintArea0").append(node);
                }
                index = 0 ;
                    for (var i = 0 ; i < data.data.header.length ; i++) {
                        for (var j = 0 ; j < data.data.data.length ; j++) {
                            if (data.data.data[j][data.data.header[i]] === null) continue;
                            $(".distributionDate")[index].innerText = beginDistributionDate;
                            $(".router")[index].innerText = routerName
                                + '-' + data.data.data[j].label ;
                            $(".customer")[index].innerText = data.data.header[i];
                            $(".foodName")[index].innerText = foodMaterialName;
                            $(".amount")[index++].innerText = data.data.data[j][data.data.header[i]]
                                + '-' + data.data.data[j].unitName ;
                        }
                    }
                print()
            },
            error: function (status) {
                alert(status)
            }
        }
    )
</script>

</body>
</html>